package com.bing.controller.LoanProducts;

import com.bing.entity.LoanProducts.Channelnfo;
import com.bing.service.ChannelnfoService;
import com.bing.utils.idgenertor.IdGen;
import com.bing.web.BaseController;
import com.bing.web.BaseResponse;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by hurl on 2019-09-01
 */
@RestController
@RequestMapping("/channel")
@Component
@Aspect
@CrossOrigin
public class ChannelController extends BaseController {
    @Autowired
    ChannelnfoService channelnfoService;

    @ApiOperation(value = "渠道列表")
    @RequestMapping(value = "get")
    public ResponseEntity<BaseResponse> getChannelList( @RequestParam(defaultValue = "1") Integer pageNum) {
        return buildSuccessResponse(channelnfoService.getChannelList(pageNum));
    }

    @ApiOperation(value = "新增渠道")
    @RequestMapping(value = "initorchange")
    public ResponseEntity<BaseResponse> addProduct(@RequestBody Channelnfo channelnfo) {
       if (StringUtils.isEmpty(channelnfo.getChannlId())){
           channelnfoService.insertSelective(channelnfo);
       } else {
           channelnfoService.updateByPrimaryKeySelective(channelnfo);
       }
        return buildSuccessResponse();
    }

    @ApiOperation(value = "修改渠道")
    @RequestMapping(value = "update")
    public ResponseEntity<BaseResponse> updadteProduct(@RequestBody Channelnfo channelnfo) {
        return buildSuccessResponse();
    }

    @ApiOperation(value = "查看渠道明细")
    @RequestMapping(value = "detail")
    public ResponseEntity<BaseResponse> getChannelDetail(@RequestParam String channelId) {
        return buildSuccessResponse(channelnfoService.getChannelDetail(channelId));
    }


    @ApiOperation(value = "上架/下架")
    @RequestMapping(value = "updateByShelf")
    public ResponseEntity<BaseResponse> updateByShelf(@RequestBody Channelnfo channelnfo) {
        Channelnfo info = new Channelnfo();
        info.setChannlId(channelnfo.getChannlId());
        info.setChannelState(channelnfo.getChannelState());
        channelnfoService.updateByPrimaryKeySelective(info);
        return buildSuccessResponse();
    }

}
